package com.puppet.building182.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.puppet.building182.pojo.Result;
import com.puppet.building182.pojo.VO.RoleVo;
import com.puppet.building182.pojo.VO.UserVo;
import com.puppet.building182.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/role")
public class RoleController {
    @Autowired
    private RoleService roleService;
    @GetMapping("/getRole/{id}")
    public Result<?> getRole(@PathVariable("id") Integer id ) {
        return Result.ok(roleService.getRole(id));
    }

    @PostMapping("/savaRoleByUid/{uid}")
    public Result<?> saveRoleByUid(@PathVariable("uid") Integer uid, @RequestBody List<Integer> roleIds) {
       return Result.ok(roleService.saveRoleByUid(uid,roleIds));
    }
//角色管理正式流程
@GetMapping("/getAllRoles/{pageNum}/{pageSize}")
    public Result<?> getAllRoles(@PathVariable("pageNum") Integer pageNum, @PathVariable("pageSize") Integer pageSize) {
    PageHelper.startPage(pageNum,pageSize);
    List<RoleVo> list = roleService.getAllRoles();
    PageInfo<RoleVo> pageInfo = new PageInfo<>(list);
    return Result.ok(pageInfo);
}
@PutMapping
    public Result<?> updateRole(@RequestBody RoleVo roleVo) {
        return Result.ok(roleService.updateRole(roleVo));
}
@GetMapping("/getrolebyid/{id}")
    public Result<?> getrolebyid(@PathVariable("id") Integer id) {
        return Result.ok(roleService.getrolebyid(id));
}
@DeleteMapping("/{id}")
    public Result<?> deleteRoleById(@PathVariable("id") Integer id) {
        return Result.ok(roleService.deleteRoleById(id));
}


}
